pub use chrono::*;
/// 日志日期格式
pub const LOG_DATE_FORMAT: &'static str = "[%Y-%m-%d][%H:%M:%S]";
/// 日志日期文件格式
pub const LOG_FILE_DATE_FORMAT: &'static str = "%Y-%m-%d_%H-%M-%S";
/// 系统日期时间
pub const STANDARD_DATETIME_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";

/// Get Current time
pub fn now() -> DateTime<Utc> {
  Utc::now()
}
/// 解析字符串
pub fn parse_str(content: &str, fmt: &str) -> Option<DateTime<Utc>> {
  Some(NaiveDateTime::parse_from_str(content, fmt).ok()?.and_utc())
}
/// 解析字符串
pub fn parse_china_str(content: &str, fmt: &str) -> Option<DateTime<FixedOffset>> {
  parse_datetime_offset(NaiveDateTime::parse_from_str(content, fmt).ok()?, FixedOffset::east_opt(8 * 3600)?)
}
/// 解析时间戳
pub fn parse_timestamp(timestamp: i64) -> Option<DateTime<FixedOffset>> {
  parse_datetime_offset(DateTime::from_timestamp(timestamp, 0)?.naive_utc(), FixedOffset::east_opt(8 * 3600)?)
}
/// 解析
pub fn parse_datetime_offset(datetime: NaiveDateTime, fixed_offset: FixedOffset) -> Option<DateTime<FixedOffset>> {
  Some(DateTime::from_naive_utc_and_offset(datetime, fixed_offset))
}
/// Get Now From China
pub fn china_now() -> Option<DateTime<FixedOffset>> {
  // 定义上海时区
  let shanghai_offset = FixedOffset::east_opt(8 * 3600)?; // UTC+8
  Some(DateTime::from_naive_utc_and_offset(Utc::now().naive_utc(), shanghai_offset))
}
